package cn.com.controller;


import cn.com.beans.BatchLine;
import cn.com.service.BatchLineService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@Controller
@RequestMapping("/batch")
public class BatchController {

    @Resource
    private BatchLineService batchLineService;

    @GetMapping
    public String findBatch(BatchLine batchLine, String baProvince, String baType, Integer year, ModelMap model){
        if(baProvince != null){
            batchLine.setBaProvince(baProvince);
        }
        if(baType != null) {
            batchLine.setBaType(baType);
        }
        if(year != null){
            batchLine.setBaYear(year);
        }
        if(baProvince == null&&baType == null && year==null){
            batchLine.setBaProvince("湖南");
            batchLine.setBaType("理科");
            batchLine.setBaYear(2020);
            BatchLine b = this.batchLineService.findBatch(batchLine);
            model.addAttribute("batch",b);
            return "select/batch";
        }
        BatchLine b = this.batchLineService.findBatch(batchLine);
        model.addAttribute("batch",b);
        return "select/batch";
    }
}
